/*
 * Main.fx
 *
 * Created on 03.11.2009, 17:53:29
 */

package javafx179labs.Safiullin.lab4;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Ellipse;
import javafx.scene.paint.Color;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.animation.transition.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.transform.Rotate;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.Group;
//Птица летит, лягушка в это время маргает. Если нажать на лягушку то поплавок
//начинает нырять, показывая поклёвку рыбы.
//При нажатии на поплавок рыба вытаскивается на леске. Причём вытаскиваются 3 разные рыбки.
//После вытаскивания рыбки можно опять нажать на лягушку и поплавок снова будет нырятью
/**
 * @author Safick
 */
//var Integer:

var jjj: Number = 0;
var iii: Number = 0;
var kkk: Number = 0;
var xxx: Number = 80;
var yyy: Number = 60;
var ccc: Number = 0;
var aaa: Number = 0;
var ooo: Number = 0;
var fone:ImageView = ImageView {
    fitWidth:640
    fitHeight:480
    image: Image {
    url: "{__DIR__}Aqua.jpg"}
    }
var Krug:Ellipse = Ellipse {
     centerX: 380, centerY: 380
     radiusX: 100
     radiusY: 40
     opacity: 1
     stroke: Color.BLUE
     fill: null
     }
var Krug2:Circle = Circle {
     centerX: 120, centerY: 300
     radius: 5
     fill:Color.YELLOW
     }
var Krug1:Ellipse = Ellipse {
     centerX: 380, centerY: 380
     radiusX: 70
     radiusY: 10
     opacity:1
     stroke: Color.BLUE
     fill: null
     }
var popl:ImageView = ImageView {
     transforms:Rotate { pivotX : 380.0, pivotY : 380.0, angle: bind iii}
     x:320
     y:240
     image: Image {
     url: "{__DIR__}poplavok1.png"}
     onMouseClicked: function( e: MouseEvent ):Void {
     delete Krug1 from Mylt.scene.content;
     delete Krug from Mylt.scene.content;
     delete  popl from Mylt.scene.content;
     if(ccc==1){insert leska into Mylt.scene.content;
             insert Karas into Mylt.scene.content;
            TiMeK.play();}
     if(ccc==2){
        delete Karas from Mylt.scene.content;
        insert leska1 into Mylt.scene.content;
        insert krasnoperka into Mylt.scene.content;
        TiMeKrasn.play();}
      if(ccc==3){
        delete krasnoperka from Mylt.scene.content;
        insert leska2 into Mylt.scene.content;
        insert okun into Mylt.scene.content;
     ccc=0;
     TiMeO.play();
     }
     }
}
var Frog:ImageView = ImageView {
     x:50
     y:260
     fitWidth:124
     fitHeight:128
     image: Image {
     url: "{__DIR__}frog.png"}
     onMouseClicked: function( e: MouseEvent ):Void {
     delete krugf from Mylt.scene.content;
     delete popl from Mylt.scene.content;
     insert Krug into Mylt.scene.content;
     insert Krug1 into Mylt.scene.content;
     insert popl into Mylt.scene.content;
     ccc++;
     iii=-20;
     TiMe.play();
     TimeFrog.stop()}
     }
var krugf:Circle = Circle {
     centerX: 120, centerY: 301
     opacity: 0
     radius: 8
     fill: Color.DARKGREEN
     }
var Kyvshinka:ImageView = ImageView {
     x:0
     y:300
     fitWidth:150
     fitHeight:193
     image: Image {
     url: "{__DIR__}kyvshinka.png"}
     }
var leftWing:ImageView = ImageView {
     fitWidth:bind xxx
     fitHeight:bind yyy
     image: Image {
     url: "{__DIR__}left.png"}
     }
var rightWing:ImageView = ImageView {
     fitWidth:bind xxx
     fitHeight:bind yyy
     image: Image {
     url: "{__DIR__}right.png"}
     }
var body:ImageView = ImageView {
     fitWidth:bind xxx
     fitHeight:bind yyy
     image: Image {
     url: "{__DIR__}body.png"}
     }
var Ptichka:Group = Group {
     layoutX:60
     layoutY:20
     opacity:1
     content: [
     leftWing,rightWing,body
       ]
     }
var Karas:ImageView = ImageView {
     transforms:Rotate { pivotX : bind Karas.x, pivotY : bind Karas.y, angle: bind 270.0+kkk }
     x: bind 330+jjj
     y: bind -jjj*jjj-jjj+500
     fitWidth:150
     fitHeight:90
     image: Image {
     url: "{__DIR__}karas.png"}
     }
var leska:Line = Line {
    startX: bind 386+jjj+kkk, startY: bind -jjj*jjj-jjj+373
    endX: bind 386+jjj, endY: 0
    strokeWidth: 1
    stroke: Color.BLACK
    }
var leska1:Line = Line {
    startX: bind 370+aaa+kkk, startY: bind -aaa*aaa-6*aaa+385
    endX: bind 370+aaa, endY: 0
    strokeWidth: 1
    stroke: Color.BLACK
    }
var leska2:Line = Line {
    startX: bind 370+ooo+kkk, startY: bind -ooo*ooo-6*ooo+410
    endX: bind 370+ooo, endY: 0
    strokeWidth: 1
    stroke: Color.BLACK
    }
var krasnoperka: ImageView = ImageView {
     transforms:Rotate {  pivotX : bind krasnoperka.x, pivotY : bind krasnoperka.y, angle: bind 90.0+kkk  }
     x:bind 420-aaa
     y:bind -aaa*aaa-6*aaa+380
     fitWidth:150
     fitHeight:90
     image: Image {
     url: "{__DIR__}Krasnoperka.png"}
     }
var okun: ImageView = ImageView {
     transforms:Rotate {  pivotX : bind okun.x, pivotY : bind okun.y, angle: bind 90.0+kkk  }
     x:bind 435-ooo
     y:bind -ooo*ooo-6*ooo+400
     fitWidth:150
     fitHeight:90
     image: Image {
     url: "{__DIR__}Okun1.png"}
     }
var FLY = SequentialTransition{
    content:[
FadeTransition{
    duration:0.6s
    node:Ptichka
    fromValue:0.0
    toValue:1.0
    repeatCount:1
    autoReverse:true
}
ParallelTransition{
    content:[
ScaleTransition{
    duration:5s
    node: Ptichka
    byX:8
    byY:8
    repeatCount:1
    autoReverse:false
}
RotateTransition{
    duration:0.2s
    node:leftWing
    byAngle:20
    repeatCount:24
    autoReverse:true
    }
RotateTransition{
    duration:0.2s
    node:rightWing
    byAngle:-20
    repeatCount:24
    autoReverse:true
    }
   ]
 }
FadeTransition{
    duration:0.6s
    node:Ptichka
    fromValue:1.0
    toValue:0.0
    repeatCount:1
    autoReverse:true
}
]
}
var TiMe:Timeline = Timeline {
     repeatCount: Timeline.INDEFINITE;
     keyFrames : [
     at (1s) { popl.y => 230;
               iii=>20;
               Krug.radiusX => 160;
               Krug.radiusY => 50;
               }
     at(1.5s)  { popl.y =>240;
               iii=>0;
               Krug1.radiusX => 140;
               Krug1.radiusY => 30;
               Krug1.opacity=>0;
               Krug.opacity=>0;
             }
     at(2s)  {popl.y => 230;
               iii=>-20;
               Krug.radiusX => 160;
               Krug.radiusY => 50;
               }
     ]
}
var TiMe1:Timeline = Timeline {
     repeatCount: Timeline.INDEFINITE;
     keyFrames : [
     at (1s) { jjj=>20}
     ]
}
var TiMeK:Timeline = Timeline {
     repeatCount: 1
     keyFrames : [
     at (1s) { jjj=>1;kkk=>10}
     at (1.5s) { jjj=>7;kkk=>-10}
     at (2s) { jjj=>14;kkk=>10}
     at (2.5s) {jjj=>21;kkk=>-10}
     at (3s) {jjj=>28;kkk=>10}
     ]
}
var TiMeKrasn:Timeline = Timeline {
     repeatCount: 1
     keyFrames : [
     at (1s) { aaa=>0;kkk=>20}
     at (1.5s) { aaa=>4;kkk=>-20}
     at (2s) { aaa=>8;kkk=>20}
     at (2.5s) {aaa=>12;kkk=>-20}
     at (3s) {aaa=>21;kkk=>20}
     ]
}
var TiMeO:Timeline = Timeline {
     repeatCount: 1
     keyFrames : [
     at (1s) { ooo=>0;kkk=>5}
     at (1.5s) { ooo=>4;kkk=>-5}
     at (2s) { ooo=>8;kkk=>5}
     at (2.5s) {ooo=>12;kkk=>-5}
     at (3s) {ooo=>21;kkk=>5}
     ]
}
var TimeFrog:Timeline = Timeline {
     repeatCount: Timeline.INDEFINITE;
     keyFrames : [
     at (1s) {krugf.opacity=>0}
     at (1.2s){krugf.opacity=>1}
     at (1.4s){krugf.opacity=>0}
     at (1.6s) {krugf.opacity=>1}
     ]
}
TimeFrog.play();
FLY.play();
var Mylt:Stage = Stage {
    title: "Мульт!!!"
    width: 640
    height: 480
    scene: Scene {
        content: [
                fone,
                Kyvshinka,
                Frog,krugf,Ptichka,popl
        ]
    }
}